package com.leapp.sk.ui.activity.personal

import android.content.Intent
import android.os.Bundle
import cc.vv.lkbasecomponent.http.LKHttp
import cc.vv.lkbasecomponent.http.lib.setting.Settings
import cc.vv.lklibrary.http.base.okhttpfactory.plugins.httpplugin.MediaTypeWrap
import com.example.baselibrary.util.LKToastUtil
import com.example.mvp.activity.BaseActivityMVP
import com.example.mvp.binder.BaseDataBinder
import com.leapp.sk.R
import com.leapp.sk.app.UPDATE_PERSONAL_INFO
import com.leapp.sk.bean.request.login.UpdatePersonalInfoRequestEntity
import com.leapp.sk.bean.response.login.UpdatePersonalInfoResponseEntity
import com.leapp.sk.binder.BaseBinder
import com.leapp.sk.inter.TopBarRightClickInterface
import com.example.util.finallist.*
import com.leapp.sk.viewdelegate.personal.PersonalIntroduceDelegate

/**
 * 个人介绍
 * @author  chaohaipeng  on 2018/8/8.
 */
class PersonalIntroduceActivity :BaseActivityMVP<PersonalIntroduceDelegate>(), TopBarRightClickInterface {
    override fun searchData() {
        httpUpdateData()
    }

    override fun initDate() {
        val introduce = intent?.getStringExtra(PERSONAL_INTRODUCE)
        viewDelegate.initEditText(introduce,this)
    }

    override fun bindEvenListener() {
    }

    override fun getDelegateClass(): Class<PersonalIntroduceDelegate> {
        return PersonalIntroduceDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return BaseBinder()
    }

    override fun initView(p0: Bundle?) {
        viewDelegate.setTitle(resources.getString(R.string.string_personal_introduce_title))
    }
    /**
     * 更新数据
     */
    private fun httpUpdateData() {
        val updatePersonalInfoRequestEntity = UpdatePersonalInfoRequestEntity()
        updatePersonalInfoRequestEntity.introduction=viewDelegate.getSubmitContent()
        LKHttp.post(UPDATE_PERSONAL_INFO, updatePersonalInfoRequestEntity, UpdatePersonalInfoResponseEntity::class.java, object : BaseCallBack<UpdatePersonalInfoResponseEntity>(this) {
            override fun onSuccess(url: String?, resultText: String?, obj: UpdatePersonalInfoResponseEntity?) {
                super.onSuccess(url, resultText, obj)
                if (obj?.code == SKCODE_200) {
                    val intent: Intent = Intent(this@PersonalIntroduceActivity, PersonalDataActivity::class.java)
                    intent.putExtra(PERSONAL_INTRODUCE,viewDelegate.getSubmitContent())
                    this@PersonalIntroduceActivity.setResult(CODE_203,intent)
                    this@PersonalIntroduceActivity.finish()
                } else {
                    LKToastUtil.showToastShort(obj?.message)
                }
            }

            override fun onFailure(url: String?, isLoading: Boolean, exceptionStr: String?) {
                super.onFailure(url, isLoading, exceptionStr)
                LKToastUtil.showToastShort(resources.getString(R.string.app_net_erro))
            }
        }
                , true, Settings(MediaTypeWrap.MEDIA_TYPE_FORM))

    }
}